img1 = imread("./img1.png");
img2 = imread("./img2.png");

img1_bw = im2bw(img1);
img2_bw = im2bw(img2);

% figure, imshowpair(img1, img1_bw, 'montage');
% figure, imshowpair(img2, img2_bw, 'montage');

%  方形结构元
% square_se = strel('square', 10);
% erode
% figure, imshowpair(img1_bw, imerode(img1_bw, square_se), 'montage');
% figure, imshowpair(img2_bw, imerode(img2_bw, square_se), 'montage');
% 
% dilation
% figure, imshowpair(img1_bw, imdilate(img1_bw, square_se),'montage');
% figure, imshowpair(img2_bw, imdilate(img2_bw, square_se),'montage');

% 圆形结构元
circle_se = strel('sphere', 6);
% 腐蚀
% figure, imshowpair(img1, imerode(img1_bw, circle_se), 'montage');
% figure, imshowpair(img2, imerode(img2_bw, circle_se), 'montage');
%
% 膨胀
% figure, imshowpair(img1_bw, imdilate(img1_bw, circle_se),'montage');
% figure, imshowpair(img2_bw, imdilate(img2_bw, circle_se),'montage');

% 菱形结构元
diamond_se = strel('diamond', 5);
% 腐蚀
% figure, imshowpair(img1_bw, imerode(img1_bw, diamond_se), 'montage');
% figure, imshowpair(img2_bw, imerode(img1_bw, diamond_se), 'montage');
% 
% 膨胀
% figure, imshowpair(img1_bw, imdilate(img1_bw, diamond_se), 'montage');
% figure, imshowpair(img2_bw, imdilate(img1_bw, diamond_se), 'montage');

% close
% figure, imshowpair(img1_bw, bwmorph(img1_bw, 'close'), 'montage');
% figure, imshowpair(img2_bw, bwmorph(img2_bw, 'close'), 'montage');

% open
% figure, imshowpair(img1_bw, bwmorph(img1_bw, 'open'), 'montage');
% figure, imshowpair(img2_bw, bwmorph(img2_bw, 'open'), 'montage');

% fingerprint image
img3 = imread("./img3.png");
img3_bw = im2bw(img3);

erode3 = imerode(img3_bw, strel('diamond', 4));
figure, imshowpair(img3_bw, erode3, 'montage'), title("腐蚀");

er_open = bwmorph(img3_bw, 'open');
figure, imshowpair(img3, er_open, 'montage'), title("腐蚀-开");

er_open_dilate = imdilate(er_open, strel('square', 2));
figure, imshowpair(img3_bw, er_open_dilate, 'montage'), title("腐蚀-开-膨胀");

